package com.travel.rabbit.controller.front;

import com.travel.rabbit.constants.Constants;
import com.travel.rabbit.dto.SignOutUserDTO;
import com.travel.rabbit.dto.UpdateUserDTO;
import com.travel.rabbit.dto.UserLoginDTO;
import com.travel.rabbit.dto.UserRegisterDTO;
import com.travel.rabbit.entity.Result;
import com.travel.rabbit.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * @author 云澜
 * @date 2023/6/16 2:20 下午
 */
@Api(tags = "用户模块")
@Controller
public class UserInfoController {

    @Resource
    private UserInfoService userInfoService;

    @ApiOperation(value = "用户注册",notes = "",tags = {"用户模块"})
    @PostMapping("/register")
    public Result registerByMobile(@RequestBody UserRegisterDTO userRegister){
        String result = userInfoService.register(userRegister);
        return Constants.success.equals(result)? Result.success() : Result.error(result);
    }

    @ApiOperation(value = "用户注销",notes = "",tags = {"用户模块"})
    @PostMapping("/signOutUser")
    public Result signOutUser(@RequestBody SignOutUserDTO signOutUserDTO){
        String result = userInfoService.signOutUser(signOutUserDTO);
        return Constants.success.equals(result)? Result.success() : Result.error(result);
    }

    @ApiOperation(value = "用户信息修改",notes = "",tags = {"用户模块"})
    @PostMapping("/updateUserMsg")
    public Result updateUserMsg(@RequestBody UpdateUserDTO updateUserDTO){
        String result = userInfoService.updateUserMsg(updateUserDTO);
        return Constants.success.equals(result)? Result.success() : Result.error(result);
    }

    @ApiOperation(value = "根据用户编码查询信息",notes = "",tags = {"用户模块"})
    @GetMapping("/findUserDetailsCode")
    public Result findUserDetailsCode(@RequestParam("userCode")String userCode){
        return Result.success(userInfoService.findUserDetailsCode(userCode));
    }

    @ApiOperation(value = "用户登录",notes = "",tags = {"用户模块"})
    @GetMapping("/login")
    public Result login(@RequestBody UserLoginDTO userLoginDTO){
        String result = userInfoService.login(userLoginDTO);
        return Constants.success.equals(result)? Result.success() : Result.error(result);
    }


}
